<?php
	//Calculate file movie to play
	switch(intval($this->input->get('p'))):
		case 2:
			$movie_file_name = "movie_file_name2";
			$movie_file_ext = "movie_file_ext2";
		break;
		case 3:
			$movie_file_name = "movie_file_name3";
			$movie_file_ext = "movie_file_ext3";
		break;				
		case 0:
		case 1:		
		default:
			$movie_file_name = "movie_file_name1";
			$movie_file_ext = "movie_file_ext1";
	endswitch;
?>
<div id="left_side">
	<!--Movie Header-->
	<?php echo $movie_header;?>
	<!--Music Player-->
	<div id="movie_play_bg">
		<script type='text/javascript'>
		<!--// <![CDATA[
		var OA_zones = {
			'ads_top' : 131,
			'ads_bottom' : 128
		}
		// ]]> -->
		</script>
		<script type='text/javascript' src='http://ads.you2play.com/openx/delivery/spcjs.php'></script>		
		<div id="movie_play_ads_top">
			<script type='text/javascript'>
			<!--// <![CDATA[
				OA_show('ads_top');
			// ]]> -->
			</script>
		</div>
		<div id="movie_play_object">
			<?php if(!empty($dataResult->movie_embed)):?>
				<?php echo $dataResult->movie_embed;?>
			<?php else:?>
				<!--Vdo Player-->
				<div id="vdoPlayer">
					<?php if($this->agent->is_mobile()):?>
						<video id='my_video' controls preload='none'></video>
					<?php endif;?>
				</div>
			<?php endif;?>
		</div>
		<div id="movie_play_ads_bottom">
			<script type='text/javascript'>
			<!--// <![CDATA[
				OA_show('ads_bottom');
			// ]]> -->
			</script>	
		</div>
	</div>
	<div itemscope itemtype="http://schema.org/Movie" class="movie_block">
		<div class="padding">
			<h1 itemprop="name"><?php echo $dataResult->movie_name;?></h1>
			<span class="view">ดู <?php echo number_format($dataResult->views);?> ครั้ง</span>
			<div class="clear"></div>
			<!--Movie Share-->
			<?php echo $module_facebook_plugins_share;?>
			<div id="movie_description">
				<div class="image">
					<?php echo exec_image(array(
						'folder' => 'movie',
						'dimension' => '190x306',
						'file_name' => @$dataResult->image{0}->movie_file_name.'.'.@$dataResult->image{0}->movie_file_ext,
						'alt' => ''.@$dataResult->movie_name.'',	
						'title' => ''.@$dataResult->movie_name.''	
						)
					);?>		
				</div>
				<div class="info">
					<?php //if(!$dataResult->is_video_clip):?>
					<ul id="movie_nav_file">
						<li><a href="<?php echo current_url().'?'.query_string(array('p'));?>p=1" <?php echo (intval($this->input->get('p')) <= 1 ? 'class="active"':'');?>><?php echo ($dataResult->is_video_clip ? 'คลิปวีดีโอ':'ตัวอย่างหนัง');?> 1</a></li>
						<?php if(!empty($dataResult->movie_file_name2)):?>
						<li><a href="<?php echo current_url().'?'.query_string(array('p'));?>p=2" <?php echo (intval($this->input->get('p')) == 2 ? 'class="active"':'');?>><?php echo ($dataResult->is_video_clip ? 'คลิปวีดีโอ':'ตัวอย่างหนัง');?> 2</a></li>
						<?php endif;?>
						<?php if(!empty($dataResult->movie_file_name3)):?>
						<li><a href="<?php echo current_url().'?'.query_string(array('p'));?>p=3" <?php echo (intval($this->input->get('p')) == 3 ? 'class="active"':'');?>><?php echo ($dataResult->is_video_clip ? 'คลิปวีดีโอ':'ตัวอย่างหนัง');?> 3</a></li>
						<?php endif;?>
					</ul>
					<?php //endif;?>
					<div id="movie_embed">
						<input type="text" value="&lt;iframe width=&quot;640&quot; height=&quot;382&quot; src=&quot;//www.you2play.com/player/movie/<?php echo $dataResult->movie_id;?>/<?php echo (intval($this->input->get('p')) == 0 ? 1:intval($this->input->get('p')));?>&quot; frameborder=&quot;0&quot; scrolling=&quot;no&quot; allowtransparency=&quot;true&quot;&gt;&lt;/iframe&gt;" id="page_embed" name="page_embed" readonly="true">
						<!--<input type="text" value="&lt;embed src=&quot;<?php echo js_asset_url('media/player.swf');?>&quot; flashvars=&quot;file=<?php echo other_asset_url('uploads/movie/files/'.date('Y/m/d',strtotime($dataResult->create_date)).'/'.$dataResult->{"".$movie_file_name.""}.'.'.$dataResult->{"".$movie_file_ext.""});?>&amp;image=<?php echo other_asset_url('uploads/movie/images/original/'.@$dataResult->image{0}->movie_file_name.'.'.@$dataResult->image{0}->movie_file_ext);?>&amp;autostart=false&amp;stretching=exactfit&quot; type=&quot;application/x-shockwave-flash&quot; allowfullscreen=&quot;true&quot; width=&quot;640&quot; height=&quot;386&quot; /&gt;" id="page_embed" name="page_embed" readonly="true">-->
						<a href="javascript:void(0);" id="copy_page_embed" onmouseOver="toClipboard(this)"><?php echo image_asset('movie/copy_embed.jpg','',array('width' => 73,'height' => 19));?></a>
                        <div class="clear"></div>						
					</div>
					<?php if(!$dataResult->is_video_clip):?>
					<div id="movie_label">
						<div class="subject">ผู้กำกับ:</div><div class="description" itemprop="director" itemscope itemtype="http://schema.org/Person"><span itemprop="name"><?php echo $dataResult->movie_author;?></span></div>
						<div class="subject">นักแสดง:</div><div class="description" itemprop="actor" itemscope itemtype="http://schema.org/Person"><span itemprop="name"><?php echo $dataResult->movie_actor;?></span></div>
						<div class="subject">เข้าฉาย:</div><div class="description" itemprop="datePublished" content="<?php echo $dataResult->movie_publish_date;?>"><?php echo convertDatetimeToThai($dataResult->movie_publish_date);?></div>
						<div class="subject">ประเภท:</div>
						<div class="description">
							<?php foreach($dataResult->type as $key => $value):?>
								<?php echo ($key != 0 ? ', ':'').$value->movie_type_name;?>
							<?php endforeach;?>
						</div>
					</div>
					<h2>เรื่องย่อ</h2>
					<?endif;?>
					<div><?php echo preg_replace('/\r\n|\r|\n/','<br />',$dataResult->movie_description);?></div>
				</div>
			</div>
			<div id="movie_image_relate">
				<h2>โปสเตอร์ และภาพบางส่วนจากภาพยนตร์</h2>
				<ul>
					<?php if(!empty($dataResult->image)):?>
						<?php foreach($dataResult->image as $value):?>
							<li>
								<a href="<?php echo image_asset_url('../uploads/movie/images/original/'.@$value->movie_file_name.'.'.@$value->movie_file_ext);?>" rel="gallery">
									<div class="image">
										<?php echo exec_image(array(
											'folder' => 'movie',
											'dimension' => '120x120',
											'file_name' => @$value->movie_file_name.'.'.@$value->movie_file_ext,
											'alt' => ''.@$dataResult->movie_name.'',	
											'title' => ''.@$dataResult->movie_name.''	
										)
										);?>									
									</div>
								</a>
							</li>
						<?php endforeach;?>
					<?php else:?>
						<li class="empty">ไม่มีรูปภาพที่เกี่ยวข้อง</li>
					<?php endif;?>
				</ul>
				<a href="<?php echo base_url().'';?>" class="readMore">กลับไปหน้าดูหนัง &raquo;</a>
			</div>
		</div>		
	</div>	
	<div class="movie_block">
		<h3>แสดงความคิดเห็น</h3>
		<div class="clear"></div>
		<!--Facebook Comment-->
		<?php echo $module_facebook_plugins_comment;?>			
	</div>
</div>
<div id="right_side">
	<!--Module-->
	<?php
	if(!empty($module))
	foreach($module as $value):?>
	<?php echo $value;?>
	<?php endforeach;?>
</div>
<?php if(empty($dataResult->movie_embed)): //if no embed load jwplayer?>
<!-- Hawkeye : The First Script is PreQual -->
<script type="text/javascript" language="JavaScript">
	//name: You2Play (Direct_Thailand) PreRoll 
	//created: 09/26/2013 16:51
										
	var cb = new Date().getTime();							
	var asiPqTag = false;							
	try { 								
		document.write("<sc" + "ript type='text/javascript' language='JavaScript' src='//pq-direct.revsci.net/pql?placementIdList=0qHox8&cb=" + cb + "'></sc" + "ript>");						
	} catch(err) { }						
</script>
<!-- Hawkeye: Ending The First Script -->	
<!-- Hawkeye : The second script is PASIT code for Videoplaza -->
<script type="text/javascript">
	if (typeof asiPlacements != "undefined") {
		var gwdTagData = 'adgroup=' + asiPlacements['0qHox8'].default.key + '&blob=' + asiPlacements['0qHox8'].blob;
		if ('0qHox8' in asiPlacements) {
			var gwdTagData = 'adgroup=' + asiPlacements['0qHox8'].default.key + '&blob=' + asiPlacements['0qHox8'].blob;
		}
		for(var p in asiPlacements) {
			if(asiPlacements[p].default&&asiPlacements[p].default.key){ window["ASPQ_"+p]="PQ_"+p; }
		}
	}
</script>
<!--  Hawkeye: Ending The Second Script -->	
<script type="text/javascript" language="javascript">
(function($) {
/*whatever jQuery stuff*/
	$(function(){
		var is_mobile = '<?php echo $this->agent->is_mobile();?>';
		/*var url = "<?php echo other_asset_url('uploads/movie/files/'.date('Y/m/d',strtotime($dataResult->create_date)).'/'.$dataResult->{"".$movie_file_name.""}.'.'.$dataResult->{"".$movie_file_ext.""});?>";*/
		var url = "http://vstatic.you2play.com/2013/assets/<?php echo 'uploads/movie/files/'.date('Y/m/d',strtotime($dataResult->create_date)).'/'.$dataResult->{"".$movie_file_name.""}.'.'.$dataResult->{"".$movie_file_ext.""};?>";
		if(is_mobile){
			//Set Video Source
			$('#my_video').append("<source id='mp4' src='"+url+"' type='video/mp4'>");
			$('#my_video').attr('src',""+url+"");
			$('#my_video').attr('width',640);
			$('#my_video').attr('height',382);		
			// videoplaza sdk, 4 sec time-out, callback function
			//loadScript("<?php //echo js_asset_url('media/html5-sdk-1.0.12.15.1-ea.min.js');?>",4000,initVideoplaza);
			// *** START - videoplaza plugin config ***
/*			vpConfig = {
				vphost : 'http://th-pmdplus.videoplaza.tv',
				category : 'movie',
				//tags : ['standard'],
				tags : [myDynamicTag()],
				contentId : mygwdTagData(),
				flags: [],
				playbackPosition: [] // mid-roll cue points, if any.
			}*/
			// *** END - videoplaza plugin config ***
			//Auto Play && Loop
			$('#my_video').attr('autoplay','autoplay');	
		} else {
			var playlist = [{file:""+url+""}];
/*			jwplayer('vdoPlayer').setup({
			  "autostart": true,
			  "flashplayer": "<?php //echo js_asset_url('media/player.swf');?>",
			  "playlist": playlist,
			  "width": 640,
			  "height": 382,
			  //"stretching": "exactfit",
			  "controlbar": {
			    "position": "bottom"
			  },
			  "plugins": {
			    "ova-jw": {
				  "canFireEventAPICalls": true,
			      "ads": {
			        "skipAd": {
			          "enabled": "true"
			        },
			        "schedule": [
			          {
			            "position": "pre-roll",
			            "tag": ""+generatTag('<?php //echo json_encode($dataAds);?>')+""
			          },
					  {
					  	"position": "post-roll",
						"tag": "http://ads.you2play.com/openx/delivery/fc.php?script=bannerTypeHtml:vastInlineBannerTypeHtml:vastInlineHtml&source=&format=vast&charset=UTF_8&nz=1&zones=z1=166"
					  }  
			        ]
			      }
			    }
			  },
              "provider": "http",
          	  "startparam": "starttime"	
			});*/
			jwplayer("vdoPlayer").setup({
				"autostart": true,
		      	"flashplayer": "<?php echo js_asset_url('media/player.swf');?>",
				"playlist": playlist,
		      	"width": 640,
		      	"height": 382,
		      	"plugins": "<?php echo js_asset_url('media/vp_plugin.swf');?>",
		      	"vpdomain": "http://th-pmdplus.videoplaza.tv",
		      	"vpshares": "movie",
		      	"vptags": myDynamicTag(),
			  	"vpContentid": mygwdTagData(),		      	
				"closebuttontimeout": 15,
				"vptimeout": 15000,
               	"provider": "http",
        		"startparam": "starttime"	
			});					
		}	

		//Colorbox
		$('a[rel="gallery"]').colorbox();	
	});	
})(jQuery);
</script>
<?php endif;?>
<script type="text/javascript" language="javascript">
	/*ZeroClipboard*/
	function toClipboard(e)
	{
		ZeroClipboard.setMoviePath("<?php echo base_url().'ZeroClipboard.swf';?>");
		var clip = new ZeroClipboard.Client();
	    clip.setHandCursor( true );		
		var id_copy = '#'+$(e).attr('id').replace('copy_','');	
		var id = $(e).attr('id');	
		copything = $(''+id_copy+'').val();
		clip.setText(copything);
		if (clip.div)
		{
			clip.receiveEvent('mouseout', null);
			clip.reposition(id);
		}
		else
		{
			clip.glue(id);
		}

		clip.receiveEvent('mouseover', null);
		//When User Copy Link
		clip.addEventListener('complete', function (client, text) {
			$.ajax({
				type:'post',
				url:web_path+'ajax_copy_stat',
				data:({
					movie_id:'<?php echo $dataResult->movie_id;?>'
				})	
			}).done(function(data){
				alert('คัดลอกข้องมูลลง Clipboard เรียบร้อย');
			});
		});		
	}	
</script>